﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Sharp.IO
{
    class File
    {
        public String Text;
        public String Name;
        public String Location;
        public int TotalSourceLines = 1;
        public Encoding TextEncoding;
        public void Open(String URL)
        {
            Text = "";
            StreamReader sr = new StreamReader(URL);
            Text = sr.ReadToEnd();
            TextEncoding = sr.CurrentEncoding;
            sr.Close();
            Name = Path.GetFileName(URL);
            for (int i = URL.Length - 1; i > 0; i--)
            {
                if (URL[i] == '\\' ||
                    URL[i] == '/')
                {
                    Location = URL.Substring(0, i);
                    break;
                }
            }
            foreach (char c in Text)
            {
                // Count Line Terminators to get the Line Total
                if (c == '\u000A')
                {
                    TotalSourceLines++;
                }
            }
        }
        public void Save(string URL)
        {
            StreamWriter outfile = new StreamWriter(URL);
            outfile.Write(Text);
            outfile.Close();
        }
        public bool Exists(string URL)
        {
            return System.IO.File.Exists(URL);
        }
    }
}
